/*
 * Copyright 2011 Digia Oyj - Jaakko Purhonen <jaakko.purhonen@digia.com>
 */


#ifndef TRACIMPORTPROJECTSELECTWIDGET_H
#define TRACIMPORTPROJECTSELECTWIDGET_H

#include "xmlrpcrequest.h"

#include <QWidget>
#include <QTreeWidget>
#include <QMap>

namespace XmlRpc {
class XmlRpcConnection;
//class XmlRpcIntrospect;
class XmlRpcResponse;
class XmlRpcRequest;
}

namespace Trac {

namespace Internal {

namespace Ui {
    class TracImportProjectSelectWidget;

}

struct ProjectData {
    //QString name;
    QString identifier;
    QString description;
};

class TracImportProjectSelectWidget : public QWidget
{
    Q_OBJECT
public:
    explicit TracImportProjectSelectWidget(QWidget *parent = 0);
    ~TracImportProjectSelectWidget();

    bool isValid() const;
    const QString connectionUrl();
    void setConnectionUrl(const QString &url);
    void initialize();
    void requestProjectCategories();


signals:
    void validChanged(bool value);

private slots:
    void rpcQueryCompleted(XmlRpc::XmlRpcResponse *response);
    void selectCategories(QTreeWidgetItem *selectedCategory);
    void searchProjects();
    void projectClicked(QTreeWidgetItem *selectedItem);
    void selectedProjectTextEditTextChanged();

private:
    Ui::TracImportProjectSelectWidget *ui;
    bool m_valid;
    QMap<int, ProjectData> m_projectData;
    XmlRpc::XmlRpcConnection *m_connection;
    XmlRpc::XmlRpcRequest m_request;

    void populateCategories(const QVariantList list);
    void parseCategories(const QVariantList list, QTreeWidgetItem *parentItem = 0);
    void populateProjects(const QVariantList list);


};

} // namespace Internal
} // namespace Trac


#endif // TRACIMPORTPROJECTSELECTWIDGET_H
